package com.woniuxy.controller;


import com.woniuxy.commons.model.Result;
import com.woniuxy.commons.utils.BeanCopyUtil;
import com.woniuxy.dao.model.RoleInfo;
import com.woniuxy.service.RoleInfoService;
import com.woniuxy.service.dto.AccountRoleDto;
import com.woniuxy.service.dto.RoleDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author psy
 * @since 2022-06-28
 */
@RestController
@RequestMapping("/roleInfo")
@Api(tags = "后台角色操作接口")
public class RoleInfoController {

    @Autowired
    private RoleInfoService roleInfoService;

    /**
     *超级管理员给账号授权角色时弹窗框所调用的接口
     * @param accountId 账号id
     * @return
     */
    @ApiOperation("超级管理员给账号授权角色时弹窗框所调用的接口")
    @ApiImplicitParam(name = "accountId",value = "账号id")
    @GetMapping("/loadRoleByAccount/{accountId}")
    public Result loadRoleByAccount(@PathVariable("accountId") Integer accountId){

        AccountRoleDto accountRoleDto = roleInfoService.loadRoleByAccount(accountId);

        return Result.success(200,"查询账号角色信息成功",accountRoleDto);
    }

    /**
     * 超级管理员查询所有角色信息 不分页
     * @return
     */
    @ApiOperation("超级管理员查询所有角色的信息,不分页")
    @GetMapping("/loadAllRoles")
    public Result loadAllRoles(){

        List<RoleInfo> list = roleInfoService.list();

        List<RoleDto> roleDtos = BeanCopyUtil.copyList(list, RoleDto.class);

        return Result.success(200,"查询所有角色信息成功",roleDtos);
    }



}

